package com.leyou.search.web;

import com.leyou.search.dto.SearchRequest;
import com.leyou.search.entity.Goods;
import com.leyou.search.service.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

/**
 * @author YYP
 * @date 2021/1/4
 */
@RestController
@RequestMapping("/goods")
public class SearchController {
    private final SearchService searchService;

    public SearchController(SearchService searchService) {
        this.searchService = searchService;
    }

    /**
     * 查询自动补全数据
     * @param key 用户输入的关键字
     * @return 补全的内容列表
     */
    @GetMapping("/suggestion")
    public Mono<List<String>> getSuggest(@RequestParam("key") String key) {
        return this.searchService.getSuggest(key);
    }

    /**
     * 查询业务
     * @param searchRequest
     * @return
     */
    @PostMapping("/list")
    public Mono<PageInfo<Goods>> listData(@RequestBody SearchRequest searchRequest) {

        return this.searchService.listData(searchRequest);
    }

    /**
     * 查询业务
     * @param searchRequest
     * @return
     */
    @PostMapping("/filter")
    public Mono<Map<String,List<? extends Object>>> listFilter(@RequestBody SearchRequest searchRequest) {

        return this.searchService.listFilter(searchRequest);
    }
}
